package com.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.springboot.entity.User;
import com.springboot.service.UserService;

@Controller
public class UserController {
@Autowired
private UserService userService;
	
	/**
	 * 使用JdbcTemplate新增
	 */
	@RequestMapping("/user/add")
	@ResponseBody
	public void addUser(){
		userService.createUser("zhanngsa", 20);
		userService.createUser("lsis", 21);
	}
	/**
	 * 使用Mybatis新增
	 */
	@RequestMapping("/user/addByMyBatis")
	@ResponseBody
	public void addUserByMyBatis(){
		userService.createUserByMybatis("wangwu", 23);
		userService.createUserByMybatis("laoliu", 24);
	}
	
	/**
	 * 使用Mybatis查询
	 */
	@RequestMapping("/user/get")
	@ResponseBody
	public User getUserByMybatis(){
		return userService.getUserByMybatis("zhanngsa");
	}
	/**
	 * 使用Mybatis查询+pageHelpers实现分页
	 */
	@RequestMapping("/user/getPageInfo")
	@ResponseBody
	public  PageInfo<User>  getPageInfo(){
		PageInfo<User> list=userService.findUserList(1, 2);
		return list;
	}
	
}
